home *** CD-ROM | disk | FTP | other *** search
- Path: news.sprintlink.net!datalytics!news
- From: Rob Stewart <stew@datalytics.com>
- Newsgroups: comp.lang.c++
- Subject: Re: about for loop
- Date: 8 Jan 1996 19:16:37 GMT
- Organization: Datalytics, Inc
- Message-ID: <4crqil$h4r@gold.datalytics.com>
- References: <4civik$cmg@peter.pu.edu.tw> <4cjdlq$hc5@xpat.postech.ac.kr>
- NNTP-Posting-Host: pc071.datalytics.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
-
- madincom@reuse.postech.ac.kr (Oh Jun-hee) wrote:
- >s8311116@csim49.pu.edu.tw wrote:
- >> if i write this for loop"for(i=0 ; i<=10 ; i++ )
- >> cout<< i ;
- >> the result should be " 12345678910 " or " 0123456789 " ?
- >> and what is "double linked list " ??
- >> thanks!
- >
- >I. the result of "for loop" is 0123456789 ...
- >
- >for (initialization code;
- > condition for continue;
- > the instruction which will be executed after each loop)
- > >So, the instruction i++ will be first executed after first loop.
- >
-
- We can make this even easier to understand. A for loop is
- exactly equivalent to a while loop in this way:
-
- for (a; b; c)
- {
- d;
- }
-
- becomes:
-
- a;
- while (b)
- {
- d;
- c;
- }
-
- So, your original loop becomes this:
-
- i = 0;
- while (i <= 10)
- {
- cout << i;
- i++;
- }
-
- As you can see, this will insert 0, 1, 2,..., 9, 10 onto cout,
- giving the result "012345678910."
-
- --
- Robert Stewart | My opinions are usually my own.
- Datalytics, Inc.
- (513)226-7700
- stew@datalytics.com
-
-
-